<@mits.headerDiv />
<div class="Main" id="Main">
	<!--屏幕切换-->
	<!--左边-->

	<!--右边-->
	<div class="Main_body" id="Main_body">
			  <div class="Main_bodyListBar">
				<div class="Main_bodyListBar_head"><span>角色信息</span> </div>
		<@mits.showActionMsg />
	    <div class="Main_bodyListBar_body">
				  	<table border="0" cellspacing="1" cellpadding="0" class="addTable" >
				  	<form name="roleForm" id="roleForm" action="" method="post">
						<tr>
							
							<td class="title">角色名称：<em>*</em></td>
							<td class="content" ><input type="text" name="platformRole.roleName" id="platformRole.roleName" maxlength="50" dataType="Require"  msg='角色名称不能为空' class="input_short"/></td>
					  		<td class="title">状态:</td>
							<td class="content">
							<input type="radio" name="platformRole.status" id="platformRole.status" value="1" checked="checked" />有效
							<input type="radio" name="platformRole.status" id="platformRole.status" value="0"/>无效
							</td>
						</tr>
						
						<tr bgcolor="#f9faf5">
							<td class="title">角色说明:</td>
							<td class="content2" colspan="3"><textarea name="platformRole.remark" id="platformRole.remark" class="textarea_long"></textarea></td>
					  	</tr>
						<tr bgcolor="#ffffff">
							<td class="content"  colspan="4">权限列表:</td>
							
						</tr>
						<#assign permissions = action.getPermissionList(null)>
						<#if permissions?exists>
						 <#list permissions as permission>
						<#assign permissionsLevel1 = action.getPermissionList(permission.id)>
						<#if permissionsLevel1?exists>
						<#assign i = 1>
                        <#list permissionsLevel1 as level1>
                        	
                        	<tr <#if i%2 == 0>bgcolor="#f9faf5" </#if>>

                                                                                   
							  <td class="title"><input type="checkbox" id="pid_${level1.code?if_exists}" name="permissionIds" value="${level1.id?if_exists}" onclick="setCheckBoxCheckedForCode(this,'roleForm','permissionIds')"/>${level1.name?if_exists}：</td>														
							<#assign children = action.getPermissionList(level1.id)>
							<#if children?exists>
							<td class="content2" colspan="3">
                        	<#list children as level2>
                        	  <input type="checkbox" id="pid_${level2.code?if_exists}" name="permissionIds" value="${level2.id?if_exists}" onclick="setCheckBoxParent(this,'roleForm','permissionIds');<#if (level2.dependonCode)?exists && !level2.dependonCode.equals('')>setSpecialCheckboxOn(this,'roleForm','permissionIds','pid_${level2.dependonCode?if_exists}')<#else>setSpecialCheckbox(this,'roleForm','permissionIds');</#if>"/>                                                    
							 ${level2.name?if_exists}												
							 </#list>
							 </td>	
                        </#if>                       	
							</tr>
							<#assign i=i+1>
                        </#list>
                        </#if>
	                        </#list>
                        </#if>			
					</form>
					</table>
			</div>
				<div class="Main_bodyListBar_bottom">
				  <div class="Main_bodyListBar_button">
				  						 <input type="button" class="button" value="保存" onclick="saveRole()" />
						 <input type="button" class="button" onclick="returnBack()" value="返回" />  
				  </div>
					
				</div>
			<div class="Main_bodyListBar_foot"></div>
		  </div>
		</div>
	
</div>
<@mits.footerDiv />
<script language="javascript">
  function returnBack() {
  window.location = "${base}/auth/system/initRoleList.action?cleanSucMsg=true";
 }
function checkPermission() {
 	 var flag = false;
	 var arr = document.getElementsByName('permissionIds');
	 
	 for(var i=0;i<arr.length;i++)
	 {
	 	if(arr[i].checked){
	 		 flag = true;
	 	}
	 }
	 return flag;
}
 function saveRole() {
   if(Validator.Validate($('roleForm'),3)){
   	if(!checkPermission()) {
	  alert("请选择权限点");
      return;
	 }
   	 	$('roleForm').action="${base}/auth/system/saveRole.action";
    	$('roleForm').submit();
    }
 }
  function saveAndAddRole() {
   if(Validator.Validate($('roleForm'),3)){
   	if(!checkPermission()) {
	  alert("请选择权限点");
      return false;
	 }
    $('roleForm').action="${base}/auth/system/saveAndAddRole.action";
    $('roleForm').submit();
    return true;
   } 
 }





function setCheckBoxCheckedForCode(th,form,id){
     var list=eval("document."+form+"['"+id+"']");
     if(list==null||list=="undefined"){
     	return;
     }
     if(list.type=="checkbox"){
     	if(list.id.indexOf(th.id)==0){
     	    if(th.checked){
              list.checked=true;
            }else{
              list.checked=false;
          }
     	}
     }else{
 	   for(var i=0;i<list.length;i++){
 	   	  if(list[i].id.indexOf(th.id)==0){
           if(th.checked){
              list[i].checked=true;
            }else{
              list[i].checked=false;
          }
       }
       }
     }
     setCheckBoxParent(th,form,id);
}

function setCheckBoxParent(th,form,allid){
    var id = th.id.substr(0,th.id.length-3);
	var list=eval("document."+form+"['"+id+"']");
	if(list==null||list=="undefined"){
     	return;
     }
	if(list.type=="checkbox"){
     	    if(th.checked){
              list.checked=true;
              setCheckBoxParent(list,form,allid);
            }else{
              if(!checkChildStatus(list,form,allid)){
              	if(list.id!='pid_040008'){
              		list.checked=false;
              	}
              	setCheckBoxParent(list,form,allid);
              }
            }
     }
}

function checkChildStatus(th,form,allid){
	var list=eval("document."+form+"['"+allid+"']");
	if(list==null||list=="undefined"){
     	return false;
    }
    for(var i=0;i<list.length;i++){
 	   	  if(list[i].id!=th.id && list[i].id.indexOf(th.id)==0){
           if(list[i].checked){
              return true;
            }
          } 
    }
    return false;    
}



function setSpecialCheckbox(th,form,allid){
  var id = th.id.substr(0,th.id.length-3);
  var list=eval("document."+form+"['"+id+"']");
  if(list==null||list=="undefined"){
     return;
  }
  if(th.checked==false){
     if(list.type=="checkbox"){
     	if(list.id!='pid_040011'){
     		setChildStatus(id,form,allid);
     	}
     	     	
     	if(!checkChildStatus(list,form,allid)){     	
	     	if(list.id!='pid_040008'){
	     		list.checked=false;
	     	}     	
     	}
     }
  }
}

function setChildStatus(id,form,allid){
	var list=eval("document."+form+"['"+allid+"']");
	if(list==null||list=="undefined"){
     	return;
    }
    for(var i=0;i<list.length;i++){
 	   	  if(list[i].id!=id && list[i].id.indexOf(id)==0){
           	list[i].checked=false;
          } 
    } 
}




function setSpecialCheckboxOn(th,form,id,value){
       var list=eval("document."+form+"['"+id+"']");
       if(list==null||list=="undefined"){
     	return;
       }
       for(var i=0;i<list.length;i++){
 	   	  if(list[i].id.indexOf(value)==0){ 	   	  
           if(th.checked){ 
              list[i].checked=true;  
            }
       }
       } 
}
</script>

